import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { StorageItemInfo } from "./StorageItemInfo";
import { ItemData } from "../../../resource/info/ItemData";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { CareerUtil } from "../../common/util/CareerUtil";
import { Cache } from "../../../cache/Cache";
import { ObjCreate } from "../../common/ObjCreate";
import { BaseItem } from "../../common/BaseItem";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { GuildEventName } from "../GuildEventName";
import { DragEvent } from "../../../../../com/mui/events/DragEvent";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { EventName } from "../../../mvc/EventName";
import { Language } from "../../../../../extend/language/Language";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { SPlayerItem } from "../../../../../Message/Public/SPlayerItem";
type int = number;
//class StorageItemRenderer
    
    export  class StorageItemRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            super.data = arg1;
            this._storageItemInfo = arg1 as StorageItemInfo;
            this._playerItem = this._storageItemInfo.playerItem;
            this._baseItem.dragSource = this._storageItemInfo;
            if (this._playerItem) 
            {
                loc1 = new ItemData(this._playerItem);
                this._baseItem.itemData = loc1;
            }
            else 
            {
                this._baseItem.itemData = null;
            }
            if (this._storageItemInfo.isExtend) 
            {
                this._noHoleBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.NoHole);
            }
            else 
            {
                this._noHoleBg.bitmapData = null;
            }
            if (loc1 && !CareerUtil.isCareerSuit(loc1.itemInfo.item.career, Cache.instance.role.entityInfo.career)) 
            {
                this._baseItem.meetCareer = true;
            }
            else 
            {
                this._baseItem.meetCareer = false;
            }
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 38, 38, this, ImagesConst.PackItemBg);
            this._noHoleBg = GlobalClass.getBitmap(ImagesConst.NoHole);
            this._noHoleBg.x = 1;
            this._noHoleBg.y = 1;
            this._noHoleBg.width = 34;
            this._noHoleBg.height = 34;
            this.addChild(this._noHoleBg);
            this._baseItem = new BaseItem();
            this._baseItem.width = 32;
            this._baseItem.height = 32;
            this._baseItem.move(2, 2);
            this.addChild(this._baseItem);
            this._baseItem.mouseEnabled = true;
            this._baseItem.mouseChildren = false;
            this._baseItem.doubleClickEnabled = true;
            this._baseItem.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.onItemDoubleClickHandler);
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            if (arg1 && this._playerItem) 
            {
                this._baseItem.filters = [FilterConst.itemChooseFilter];
            }
            else 
            {
                this._baseItem.filters = [];
            }
            return;
        }

        /* internal  */onItemDoubleClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._playerItem) 
            {
                Dispatcher.dispatchEvent(new DataEvent(GuildEventName.WarehouseItemDoubleClick, this._playerItem));
            }
            return;
        }

        /* internal  */onThrowHandler(arg1: DragEvent): void
        {
            var e: DragEvent;
            var dragItem: Object;
            var itemData: ItemData;
            var htmlContent: string;
            var onClickHandler: Function;

            var loc1;
            itemData = null;
            htmlContent = null;
            e = arg1;
            dragItem = e.dragItem;
            if (dragItem && dragItem is BaseItem) 
            {
                itemData = (dragItem as BaseItem).itemData;
            }
            if (itemData) 
            {
                onClickHandler = (arg1: int): void
                {
                    if (arg1 == Alert.OK) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarehouseDestroy, itemData.uid));
                        Alert.resetToDefault();
                    }
                    return;
                }
                htmlContent = Language.getStringByParam(57275, ItemsUtil.getItemName(itemData), itemData.itemAmount);
                Alert.show(htmlContent, null, Alert.OK | Alert.CANCEL, null, onClickHandler);
            }
            return;
        }

        /* internal */ /* var */_noHoleBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_playerItem: SPlayerItem;

        /* internal */ /* var */_storageItemInfo: StorageItemInfo;
    }
